#ifndef __DEF_REPPRT_H__
#define __DEF_REPPRT_H__

#include <wx/wx.h>
#include <wx/print.h>
#include <wx/tglbtn.h>
#include <vector>
#include "appconstant.h"
#include "dbkakeibo.h"

class DrawObject
{
public:
	DrawObject() {
		Clear();
	}
	void Clear(void) {
		message.Clear();
		position.x = 0;
		position.y = 0;
		fontcolor = *wxBLACK;
	}
	wxString message;
	wxPoint position;
	wxFont font;
	wxColor fontcolor;
};
WX_DECLARE_OBJARRAY(DrawObject,DrawObjectArray);

class ReportCanvas: public wxScrolledWindow
{
public:
	ReportCanvas(wxWindow *parent, const wxPoint &pos, const wxSize &size);
	~ReportCanvas(void)
	{ 
	}

	void SetReportMode(int type);
	void Draw(wxDC *dc);
	void SetPageInfo(const wxPageSetupDialogData &ps);
	void SetZoom(double x, double y);
protected:
	//void OnPaint(wxPaintEvent &event);
	void OnDraw(wxDC &dc);
	void OnMouse(wxMouseEvent &event);
	void OnSized(wxSizeEvent &event);
	void OnScrolled(wxScrollWinEvent &event);

	void ZoomedFunction(const wxSize &size);
private:
	DECLARE_EVENT_TABLE()

	int repmode;
	wxPageSetupDialogData pageInfo;
	wxSize realsize;
	double zoomx;
	double zoomy;
};
class ReportPrintout: public wxPrintout
{
public:
	ReportPrintout(wxWindow *parent, const wxString &title = wxEmptyString);
	ReportPrintout &operator =(const ReportPrintout &pout);

	bool OnPrintPage(int page);
	void GetPageInfo(int *minPage, int *maxPage, int *selPageFrom, int *selPageTo);
	bool HasPage(int page);
	int GetTotalPageNumber(void);
	bool OnBeginDocument(int startPage, int endPage);
	void OnPreparePrinting();

	void SetReportType(int type) { report_type = type; }
	void SetReportTitle(const wxString &report_title) { title = report_title; }
	void SetHeaderString(wxArrayString &report_header);
	void SetFooterString(wxArrayString &report_footer);
	void SetHeaderFooterLine(bool header, bool footer) { headerline = header; footerline = footer; }
	void SetReportMargin(int topm, int leftm, int rightm, int bottomm);
	void SetTextFont(const wxFont &font) { textfont = font; }
	void SetSpaceBetweenLine(int spaces) { linespace = spaces; }
	void SetDataNumberPerPage(int line) { data_perpage = line; }
	void SetOptions(wxArrayInt &opt);
	void Bind_DB_day(std::vector<DB_day>::iterator st, std::vector<DB_day>::iterator ed);
	void Bind_DB_total(DB_total &db) { dbtotal = db; }
	void Bind_DB_reserved(DB_reserved &db, int diff);
	void Bind_DB_weeklymonthly(DBL_WeeklyReport &db);
	void SetSearchConditions(wxArrayString arr) { searchconditions = arr; }
	void DrawPage(wxDC *dc, int page);
protected:
	wxString GetHeaderEscapeString(const wxString &str, int page);
	void DrawHeader(wxDC *dc, int page, float mm_to_logi);
	void DrawFooter(wxDC *dc, int page, float mm_to_logi);
	void DrawDayReport(wxDC *dc, int page, float mm_to_logi, int pw, int ph);
	void DrawWeeklyMonthlyReport(int type, wxDC *dc, int page, float mm_to_logi, int pw, int ph);
	void DrawSearchReport(wxDC *dc, int page, float mm_to_logi, int pw, int ph);
private:
	wxWindow *frame;
	int report_type;
	std::vector<DB_day> dbdata;
	DB_total dbtotal;
	DB_reserved dbreserve;
	int reservediff;
	DBL_WeeklyReport dbweekly;
	wxString title;
	wxString header[3];
	wxString footer[3];
	bool headerline;
	bool footerline;
	wxPoint margin_tl;
	wxPoint margin_br;
	wxFont titlefont;
	wxFont textfont;
	int data_perpage;
	int linespace;
	wxArrayInt options;
	int startdataindex;
	int oldpage;
	wxArrayString searchconditions;
};
class ReportDialog: public wxDialog
{
public:
	ReportDialog(wxWindow *parent);
	~ReportDialog(void) { }

	void Bind_PageData(wxPageSetupDialogData *ps);
	void Bind_Setup(DB_setting &setdb);
protected:
	wxPanel *repControl;
		wxButton *ctrlOpen;
		wxButton *ctrlSave;
		wxButton *ctrlClose;
		wxButton *ctrlClear;
		wxChoice *lctrlZoom;
	ReportCanvas *repCanvas;

	void ctrlClose_clicked(wxCommandEvent &event);
	void lctrlZoom_changed(wxCommandEvent &event);
private:
	DECLARE_EVENT_TABLE()
	wxPageSetupDialogData *pageInfo;
};
enum {
	repdlg_close = 600,
	repdlg_zoom,
	repdlg_flabel,
	repdlg_fline,
	repdlg_fform,
	repdlg_fbox,
	repdlg_fimage,

};

#endif